import 'package:ball_lion/utils/widget_utils.dart';
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:get/get.dart';
import 'package:ball_lion/resources/colours.dart';
import 'package:ball_lion/utils/utils.dart';
import 'package:ball_lion/widgets/base/wqs_button.dart';

import 'base/wqs_text.dart';

class BottomPickerWidget extends StatelessWidget {
  final List<String> items;
  final String? title;
  final int initialIndex;
  final String? eventId;
  late FixedExtentScrollController controller;
  BottomPickerWidget(this.items,
      {super.key, this.title, this.initialIndex = 0, this.eventId}) {
    controller = FixedExtentScrollController(initialItem: initialIndex);
  }
  // : ;

  @override
  Widget build(BuildContext context) {
    return BottomSheet(
      enableDrag: false,
      clipBehavior: Clip.hardEdge,
      shape: RoundedRectangleBorder(
          borderRadius: BorderRadius.only(
              topLeft: Radius.circular(24), topRight: Radius.circular(24))),
      onClosing: () {},
      builder: (context) {
        return Container(
            // padding: EdgeInsets.all(10),
            // shape: RoundedRectangleBorder(
            //     borderRadius: BorderRadius.only(
            //         topLeft: Radius.circular(10), topRight: Radius.circular(10))),
            // height: 250,
            color: Colors.white,
            child: SafeArea(
              child: Column(mainAxisSize: MainAxisSize.min, children: <Widget>[
                Container(
                  height: 60,
                  //padding: EdgeInsets.only(left: 16, right: 16),
                  child: Row(
                    mainAxisAlignment: MainAxisAlignment.spaceBetween,
                    children: <Widget>[
                      Expanded(
                          flex: 1,
                          child: QsText('取消',
                                  textAlign: TextAlign.center,
                                  fontSize: 16,
                                  fontWeight: FontWeight.w400,
                                  color: Colours.N9)
                              .center
                              .tap(() => Navigator.pop(context, false))),
                      Expanded(
                          flex: 3,
                          child: QsText(title ?? '',
                              textAlign: TextAlign.center,
                              fontSize: 17,
                              fontWeight: FontWeight.w500,
                              color: Colours.N9)),
                      Expanded(
                          flex: 1,
                          child: QsText("确定",
                                  textAlign: TextAlign.center,
                                  fontSize: 16,
                                  fontWeight: FontWeight.w500,
                                  color: Colours.main)
                              .center
                              .tap(() =>
                                  Get.back(result: controller.selectedItem)))
                    ],
                  ),
                ),
                DefaultTextStyle(
                  style: const TextStyle(
                    color: Colours.text,
                    fontSize: 22,
                  ),
                  child: SizedBox(
                    height: 240,
                    child: CupertinoPicker(
                      scrollController: controller,
                      selectionOverlay:
                          const CupertinoPickerDefaultSelectionOverlay(
                        background: Colours.black11,
                      ),

                      diameterRatio: 1,
                      // offAxisFraction: 0.2, //轴偏离系数
                      // useMagnifier: true, //使用放大镜
                      // magnification: 1.5, //当前选中item放大倍数
                      itemExtent: 48, //行高
                      // backgroundColor: Colors.amber, //选中器背景色
                      onSelectedItemChanged: (value) {
                        // print("value = $value, 性别：${pickerChildren[value]}");
                      },
                      children: items.map((data) {
                        return Center(
                          child: QsText(data),
                        );
                      }).toList(),
                    ),
                  ),
                ),
                // Padding(
                //   padding:
                //       EdgeInsets.only(top: 30, bottom: 20, left: 16, right: 16),
                //   child: Row(children: [
                //     Flexible(
                //       child: QsButton(
                //         width: double.infinity,
                //         height: 44,
                //         backgroundColor: Colours.greyF2,
                //         foregroundColor: Colours.grey66,
                //         borderRadius: 8,
                //         onPressed: () {
                //           Get.back();
                //         },
                //         text: '取消',
                //       ),
                //     ),
                //     const SizedBox(width: 16),
                //     Flexible(
                //       child: QsButton(
                //         width: double.infinity,
                //         height: 44,
                //         backgroundColor: Colours.main,
                //         foregroundColor: Colours.white,
                //         borderRadius: 8,
                //         onPressed: () {
                //           if (eventId != null) {
                //             Utils.onEvent(eventId!, params: {
                //               eventId!: '${controller.selectedItem + 1}'
                //             });
                //           }
                //           Get.back(result: controller.selectedItem);
                //         },
                //         text: '确定',
                //       ),
                //     )
                //   ]),
                // ),
              ]),
            ));
      },
    );
  }
}
